/*****************************************************************************
* Copyright (c) 2014,H.B.
* All rights reserved.
* 
* FileName : DtvDescrambler.java
* Description : define DtvDescrambler
* 
* Version : 0.0.0
* Author : HB   Reviewer : 
* Date : 2014-07-08
* Record : Create
*
* History : 
* (1) Version : 0.0.0
*     Author : HB   Reviewer : 
*     Date : 2014-07-08
*     Record : Create
****************************************************************************/

package hb.dtv;


public class DtvDescrambler
{
	static public final int CA_NORMAL	=	0;
	static public final int CA_ADVANCED	=	1;

	static public final int CSA2		=	0;
	static public final int CSA3		=	1;
	static public final int AES_IPTV	=	2;
	static public final int AES_ECB		=	3;
	static public final int AES_CI		=	4;
	static public final int DES_CI		=	5;
	static public final int DES_CBC		=	6;
	static public final int AES_NS		=	7;
	static public final int SMS4_NS		=	8;
	static public final int SMS4_IPTV	=	9;
	static public final int SMS4_ECB	=	10;
	static public final int SMS4_CBC	=	11;
	static public final int AES_CBC		=	12;
	static public final int DES_IPTV	=	13;
	static public final int TDES_IPTV	=	14;
	static public final int TDES_ECB	=	15;
	static public final int TDES_CBC	=	16;

	static public final int ENTROPY_REDUCTION_CLOSE	=	0;
	static public final int ENTROPY_REDUCTION_OPEN	=	1;
 
	final private int mJniPtr;

	DtvDescrambler(int ptr)
	{
		mJniPtr=ptr;
	}

	public void Release()
	{
		nativeRelease(mJniPtr);
	}

	public void AssociateChannel(DtvChannel channel)
	{
		nativeAssociateChannel(mJniPtr,channel.mJniPtr);
	}

	public void DisassociateChannel(DtvChannel channel)
	{
		nativeDisassociateChannel(mJniPtr,channel.mJniPtr);
	}
	
	public void  AssociatePid(DtvDemux demux,int pid)
	{
		nativeAssociatePid(mJniPtr,demux.mJniPtr,pid);
	}

	public void  DisassociatePid(DtvDemux demux,int pid)
	{
		nativeDisassociatePid(mJniPtr,demux.mJniPtr,pid);
	}

	public void SetEvenKey(byte[] evenKey)
	{
		nativeSetEvenKey(mJniPtr,evenKey);
	}

	public void SetOddKey(byte[] oddKey)
	{
		nativeSetOddKey(mJniPtr,oddKey);
	}
	
	@Override
	public boolean equals(Object o) 
	{
		 if (this == o) return true;
		 if (!(o instanceof DtvDescrambler)) return false;
		 DtvDescrambler d=(DtvDescrambler)o;
		 if(mJniPtr==d.mJniPtr)return true;
		 return nativeGetHandle(mJniPtr)==nativeGetHandle(d.mJniPtr);
	}

	@Override
	protected void finalize() throws Throwable
	{
		nativeDestroy(mJniPtr);
		super.finalize();
	}

	private native static void nativeAssociateChannel(int jniPtr,int channel);
	
	private native static void nativeDisassociateChannel(int jniPtr,int channel);
		
	private native static void nativeAssociatePid(int jniPtr,int demux,int pid);
	
	private native static void nativeDisassociatePid(int jniPtr,int demux,int pid);
	
	private native static void nativeSetEvenKey(int jniPtr,byte[] evenKey);
	
	private native static void nativeSetOddKey(int jniPtr,byte[] oddKey);
		
	private native static int nativeGetHandle(int jniPtr);
	
	private native static void nativeRelease(int jniPtr);

	private native static void nativeDestroy(int jniPtr);
}

